package com.smh.aiagent.rag;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetriever;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetrieverOptions;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.advisor.RetrievalAugmentationAdvisor;
import org.springframework.ai.chat.client.advisor.api.Advisor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author shiminghui
 * @date 2025/6/1 17:23
 * @description: TODO
 */
@Configuration
@Slf4j
public class LoveAppRAGCloudAdvisorConfig {


    @Value("${spring.ai.dashscope.api-key}")
    private String apiKey;

    @Bean
    public Advisor loveAppRAGCloudAdvisor() {

        // 创建 文档检索器
        DashScopeDocumentRetriever dashScopeDocumentRetriever = new DashScopeDocumentRetriever(new DashScopeApi(apiKey), DashScopeDocumentRetrieverOptions.builder()
                .withIndexName("恋爱大师") // 知识库的 名称
                .withEnableReranking(false) // 是否开启reranking
                .withEnableRewrite(false) // 是否开启rewrite 重写用户消息
                .build());

        // 创建 RAG的 Advisor
        return RetrievalAugmentationAdvisor.builder()
                .documentRetriever(dashScopeDocumentRetriever)
                .build();
    }


}
